// pages/wuliurongqiguanli/nav_check_gzcbl/check_gzcbl.js
const mybehavior = require("../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    frock_number: "",
    baseUrl: "https://logisticsengineering.gree.com/container_manage_api/diy_frock_manage",
    list: [],
    page_size: 5,
    page: 1,
    total: 0,
    page_all: 0,
    all_total: 0,
    pan_total: 0,
  },
  // 扫描
  scan1() {
    const self = this;
    wx.scanCode().then((res) => {
      const label_code = res.result;
      wx.showLoading({
        title: "loading"
      })
      console.log(label_code);
      setTimeout(function () {
        wx.hideLoading()
        self.setData({
          frock_number: label_code
        })
        self.searchData()
      }, 500)
    }).catch(err => {
      console.log(err);
    });
  },
  // 扫描查询工装车
  Submit() {
    let url = this.data.baseUrl + "/update_pan_frock"
    let data = {
      frock_number: this.data.frock_number,
      frock_name: this.data.frock_name,
    }
    this.post(url, data).then(res => {
      console.log("提交盘点", res)
      if (res.code == 20000) {
        this.searchData()
        wx.showToast({
          title: res.msg,
          icon: 'success'
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 查询按钮
  searchData() {
    let self = this;
    let url = self.data.baseUrl + "/query_pan_frock"
    let data = {
      page_size: self.data.page_size,
      page_num: self.data.page,
      frock_number: self.data.frock_number,
    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        let show_list = res.data.data1
        let frock = show_list[0].frock_name
        self.setData({
          list: show_list,
          page_all: Math.ceil(res.data.total / self.data.page_size),
          total: res.data.total,
          all_total: res.data.all_total,
          pan_total: res.data.pan_total,
          frock_name: frock
        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
        self.setData({
          list: [],
          page_size: 5,
          page: 1,
          total: 0,
          page_all: 0,
          all_total: 0,
          pan_total: 0,
        })
      }
    }).catch(err => {
      self.setData({
        list: [],
        page_size: 5,
        page: 1,
        total: 0,
        page_all: 0,
        all_total: 0,
        pan_total: 0,
      })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 分页
  onPageChange(e) {
    // console.log("xxx",e.detail.sonParam);
    let p = e.detail.sonParam
    this.setData({
      page: p,
    })
    this.getDataList()
  },

  // 获取数据
  getDataList() {
    let self = this;
    let url = self.data.baseUrl + "/query_pan_frock"
    let data = {
      page_size: self.data.page_size,
      page_num: self.data.page,
      frock_number: self.data.frock_number,
    }
    this.post(url, data).then(res => {
      if (res.code == 20000) {
        let show_list = res.data.data1
        self.setData({
          list: show_list,
          page_all: Math.ceil(res.data.total / self.data.page_size),
          total: res.data.total,
          all_total: res.data.all_total,
          pan_total: res.data.pan_total,
        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: "error"
        })
        self.setData({
          list: [],
          page_size: 5,
          page: 1,
          total: 0,
          page_all: 0,
          all_total: 0,
          pan_total: 0,
        })
      }
    }).catch(err => {
      self.setData({
        list: [],
        page_size: 5,
        page: 1,
        total: 0,
        page_all: 0,
        all_total: 0,
        pan_total: 0,
      })
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDataList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})